<?php
namespace bee;

define('CONSTRUCOR_TYPE_STRING', 1);
define('CONSTRUCOR_TYPE_SESSION_ID', 2);
abstract class object
{ private $emptyValue = '';
  /**
   * @var bool __withEvents
   */
  public $__withEvents;
  protected $__objectID;

  static function getSerialized($id)
  {

  }
  public function getObjectID()
  { return $this->__objectID;
  }

	/**
	 *
	 * @param string $conString
	 * @param string $consType
	 * @return unknown_type
	 */
  function _x__construct($conString = '', $consType = CONSTRUCOR_TYPE_STRING)
  {	if($conString)
    {	switch($consType)
      { case CONSTRUCOR_TYPE_STRING:
          $arr = explode(';', $conString);
          foreach ($arr as $element)
          {	$row = explode('=', $element);
				    $attr_name = $row[0];
				    $this->$attr_name = $row[1];
			     }
			    break;
        case CONSTRUCOR_TYPE_SESSION_ID:
        	return unserialize($consType);
		  }
		}
	}

	function __toString()
	{	$refl = new \ReflectionClass(get_class($this));
	//echo $refl->name;
	$this->cls_props = $refl->getProperties();

		$ret_arr = array();
		foreach ($this->cls_props as $prop)
		{	if(gettype($this->{$prop->name}) != "object" && $prop->isPublic())
			{	if($this->{$prop->name} != $this->emptyValue)
				{ $ret_arr[$prop->name] = $prop->name . '=' . $this->{$prop->name};
				}
			}
		}
		$ret_str = implode(';', $ret_arr) . ";";
		return $ret_str;
	}

	public function __deepCopy()
	{ //return unserialize(serialize($this));
	  $new = clone $this;
	  foreach ($this as $key => $value)
	  { if($value instanceof object)
	    { $new->$key = $value->__deepCopy();
	    } else if(is_object($value))
	    {
	      $new->$key = clone $value;
	    }
	  }
	  return $new;
  }
}

